var app = angular.module("myApp",[]);
app.controller("myCtrl",function($scope,$http,$timeout){
	$scope.userName = "";
	$scope.userPword = "";
	$scope.yes = false;
	$scope.loading = "登陆";
	$scope.alert_hide = function(){
		$scope.yes = false;
	}
	
	$scope.go_singin = function(){
		location.href = "sign.html";
	}
	
	$scope.login = function(){
		$.ajax({
			type : "post",
			url  : host + "/terminal/user/login",
			data : {
				username : $scope.userName,
				password : $scope.userPword
			},
			dataType: "json",
			xhrFields: {
				withCredentials: true	//跨域名请求。XHR：XMLHttpRequest (XHR) ，基于XML技术的Http请求
	        },
	        crossDomain: true,
	        contentType: "application/x-www-form-urlencoded",//表单提交
			success : function(response){
	            if(response.code == 5000){
	        		$scope.yes = true;
	        		$scope.alert_text = response.message;
	        	}
	        	if(response.code == 2000){
	        		$scope.loading = "正在登陆中..."
	        		window.sessionStorage.login = "true";
	        		$timeout(function(){
	        			window.location.href = "index.html";
	        		},750)
	        	}
			}
		});
		
		/*var params = {
			username : $scope.userName,
			password : $scope.userPword
		};
		params = $.param(params);
        $http({
        	method : "post",
        	dataType: "json",
			withCredentials: true,	//跨域名请求。XHR：XMLHttpRequest (XHR) ，基于XML技术的Http请求
	        crossDomain: true,
	        headers:{'Content-Type': 'application/x-www-form-urlencoded'},
        	data : params,
        	async:true,
        	url : host + "/terminal/user/login"
        }).success(function(response){
        	if(response.code == 5000){
        		$scope.yes = true;
        		$scope.alert_text = response.message;
        	}
        	if(response.code == 2000){
        		$scope.loading = "正在登陆中..."
        		window.sessionStorage.login = "true";
        		$timeout(function(){
        			window.location.href = "index.html";
        		},750)
        	}
        });*/
	};
});